//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//                  不见满街漂亮妹，哪个归得程序员？  

#include "EquipInfo.h"

EquipInfo::EquipInfo(){
	//装备动态id
	id =0;
	//装备资源id
	resourtId =0;
	//主属性类型。详情见表格
	mainType = 0;
	//主属性值
	mainValue =0;
	//神器属性类型：见装备属性表
	artifactType = 0;
	//神器属性值
	artifactValue =0;
	//装备强化等级
	intensifyLv = 0;
	//装备评分
	equipNum =0;
	//是否锁定状态0否1是
	isLock = 0;
	//装备当前点化次数
	dianhuaNum =0;
	//套装效果号(显示时统计相同的效果号：再用效果号本身* 100 + 统计出来的数量)到得到显示效果id
	taozhuangEffect =0;
}

EquipInfo::~EquipInfo()
{
	reset();
}

EquipInfo* EquipInfo::clone(){
	auto ret=new  EquipInfo();
ret->id=id;
ret->resourtId=resourtId;
ret->mainType=mainType;
ret->mainValue=mainValue;
ret->artifactType=artifactType;
ret->artifactValue=artifactValue;
ret->intensifyLv=intensifyLv;
ret->equipNum=equipNum;
ret->isLock=isLock;
ret->dianhuaNum=dianhuaNum;
ret->taozhuangEffect=taozhuangEffect;
for(auto bean : addAttribute){
		ret->addAttribute.push_back(bean->clone());
}
for(auto bean : holes){
		ret->holes.push_back(bean->clone());
}
for(auto bean : anjinAtts){
		ret->anjinAtts.push_back(bean->clone());
}
for(auto bean : kungFuAndEquips){
		ret->kungFuAndEquips.push_back(bean->clone());
}
return ret;
}

void EquipInfo::reset(){
for(auto bean : addAttribute){
	if (bean)
	delete bean;
	bean=0;
}
addAttribute.clear();
for(auto bean : holes){
	if (bean)
	delete bean;
	bean=0;
}
holes.clear();
for(auto bean : anjinAtts){
	if (bean)
	delete bean;
	bean=0;
}
anjinAtts.clear();
for(auto bean : kungFuAndEquips){
	if (bean)
	delete bean;
	bean=0;
}
kungFuAndEquips.clear();
}
/**
 * 读取字节缓存
 */
bool EquipInfo::read_from(ByteBuf& buf)
{
	//装备动态id
	id = readInt64(buf);
	//装备资源id
	resourtId = readInt32(buf);
	//主属性类型。详情见表格
	mainType = readInt8(buf);
	//主属性值
	mainValue = readInt32(buf);
	//神器属性类型：见装备属性表
	artifactType = readInt8(buf);
	//神器属性值
	artifactValue = readInt32(buf);
	//装备强化等级
	intensifyLv = readInt8(buf);
	//装备评分
	equipNum = readInt32(buf);
	//是否锁定状态0否1是
	isLock = readInt8(buf);
	//装备当前点化次数
	dianhuaNum = readInt32(buf);
	//套装效果号(显示时统计相同的效果号：再用效果号本身* 100 + 统计出来的数量)到得到显示效果id
	taozhuangEffect = readInt32(buf);
	//附加属性
	short addAttribute_length = readInt16(buf);
	for (int i = 0; i < addAttribute_length; i++) {
		auto bean =new AddAttribute();
		readBean(buf, *bean);
		addAttribute.push_back(bean);
	}
	//宝石属性
	short holes_length = readInt16(buf);
	for (int i = 0; i < holes_length; i++) {
		auto bean =new HoleInfo();
		readBean(buf, *bean);
		holes.push_back(bean);
	}
	//暗金属性
	short anjinAtts_length = readInt16(buf);
	for (int i = 0; i < anjinAtts_length; i++) {
		auto bean =new AnJinAtt();
		readBean(buf, *bean);
		anjinAtts.push_back(bean);
	}
	//装备组合武功效果
	short kungFuAndEquips_length = readInt16(buf);
	for (int i = 0; i < kungFuAndEquips_length; i++) {
		auto bean =new KungFuAndEquip();
		readBean(buf, *bean);
		kungFuAndEquips.push_back(bean);
	}
	
	return true;
}

/**
 * 写入字节缓存
 */
bool EquipInfo::write_to(ByteBuf& buf)
{
	//装备动态id
	writeInt64(buf, id);
	//装备资源id
	writeInt32(buf, resourtId);
	//主属性类型。详情见表格
	writeInt8(buf, mainType);
	//主属性值
	writeInt32(buf, mainValue);
	//神器属性类型：见装备属性表
	writeInt8(buf, artifactType);
	//神器属性值
	writeInt32(buf, artifactValue);
	//装备强化等级
	writeInt8(buf, intensifyLv);
	//装备评分
	writeInt32(buf, equipNum);
	//是否锁定状态0否1是
	writeInt8(buf, isLock);
	//装备当前点化次数
	writeInt32(buf, dianhuaNum);
	//套装效果号(显示时统计相同的效果号：再用效果号本身* 100 + 统计出来的数量)到得到显示效果id
	writeInt32(buf, taozhuangEffect);
	//附加属性
	writeShort(buf, addAttribute.size());
	for (int i = 0; i < addAttribute.size(); i++) {
		writeBean(buf, *addAttribute[i]);
	}
	//宝石属性
	writeShort(buf, holes.size());
	for (int i = 0; i < holes.size(); i++) {
		writeBean(buf, *holes[i]);
	}
	//暗金属性
	writeShort(buf, anjinAtts.size());
	for (int i = 0; i < anjinAtts.size(); i++) {
		writeBean(buf, *anjinAtts[i]);
	}
	//装备组合武功效果
	writeShort(buf, kungFuAndEquips.size());
	for (int i = 0; i < kungFuAndEquips.size(); i++) {
		writeBean(buf, *kungFuAndEquips[i]);
	}
	
	return true;
}
